package com.jiazhong.mingxing.boot.boot11.顺序消息;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

@Slf4j
public class 顺序消息生产1 {

    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("jiazhong-d");
        producer.setNamesrvAddr("124.220.170.254:9876");
        producer.setDefaultTopicQueueNums(1); // 设置队列的个数 默认4个
        producer.start();
        for (int i = 1; i < 21; i++) {
            String topic = "TopicB";
            String tags = "shunxu";
            String body = "Hello,Shunxu!index:" + i;
            Message message = new Message(topic, tags, body.getBytes());
            SendResult sendResult = producer.send(message);
            log.info("sendResult={}", sendResult);
        }
        producer.shutdown();
    }
}
